<?
/*
Bitsand - a web-based booking system for LRP events
Copyright (C) 2006 Russell Peter Phillips

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

include ('inc_head_db.php');
include ('inc_admin.php');
include ('inc_head_html.php');

//Get list of players
$key = CRYPT_KEY;
$sql = "SELECT plPlayerID, " .
	"AES_DECRYPT(plFirstName, '$key') AS dFirstName, " .
	"AES_DECRYPT(plSurname, '$key') AS dSurname, " .
	"UPPER(AES_DECRYPT(plCarRegistration, '$key')) AS dCarRegistration, " .
	"chName " .
	"FROM players, characters, bookings " .
	"WHERE plPlayerID = chPlayerID AND chPlayerID = bkPlayerID AND bkDatePaymentConfirmed <> '0000-00-00' " .
	"ORDER BY ";
switch ($_GET ['sort']) {
case 'oocfirstname':
	$sql .= 'dFirstName';
	break;
case 'oocsurname':
	$sql .= 'dSurname';
	break;
case 'ic':
	$sql .= 'chName';
	break;
case 'reg':
	$sql .= 'dCarRegistration';
	break;
default:
	$sql .= 'plPlayerID';
	break;
}
$result = mysqli_query ($link, $sql);
?>

<h1><?=TITLE?> - Bookings Status</h1>

<p>
<a href = 'admin.php'>Admin</a>
</p>

<p>
Click on a column header to sort by that column. Click on a player's ID to see that player's details.
</p>

<table border = '1'>
<tr>
<th><a href = "admin_booked.php">Player ID</a></th>
<th><a href = "admin_booked.php?sort=oocfirstname">OOC First Name</a></th>
<th><a href = "admin_booked.php?sort=oocsurname">OOC Surname</a></th>
<th><a href = "admin_booked.php?sort=ic">IC Name</a></th>
<th><a href = "admin_booked.php?sort=reg">Car Registration</a></th>
</tr>

<?
while ($row = mysqli_fetch_assoc ($result)) {
	echo "<tr class = 'highlight'>\n<td>";
	echo "<a href = 'admin_viewdetails.php?pid=" . $row ['plPlayerID'] . "'>";
	echo PID_PREFIX . sprintf ('%03s', $row ['plPlayerID']) . "</a></td>\n<td>";
	echo htmlentities (stripslashes ($row ['dFirstName']));
	echo "</td>\n<td>";
	echo htmlentities (stripslashes ($row ['dSurname']));
	echo "</td>\n<td>";
	echo htmlentities (stripslashes ($row ['chName']));
	echo "</td>\n<td>";
	echo htmlentities (stripslashes ($row ['dCarRegistration']));
	echo "</td>\n</tr>";
}
?>

</table>

<?
include ('inc_foot.php');
?>
